class TaskController {
    private taskDlg : view.dlg.Task;

    constructor() {
        
    }
    
    setBubble(){
        if(taskModel.getDailyFinish().length >= Cfg.TaskCfg["daily_count"]["value"])
			Game.viewFarm.taskbg.getChildByName("bubble")["visible"] = false;
		else 
			Game.viewFarm.taskbg.getChildByName("bubble")["visible"] = true;
    }

    showTask():void{
        if(!this.taskDlg) this.taskDlg = view.dlg.Task.getTask();
        taskModel.setTask();
        this.taskDlg.openTask();
    }

    taskCommit(mode, count=1, extras=0):void{
        taskModel.setTask();
        //客户端进行判断,是否存在未完成的该模式任务
        let task = taskModel.getDailyHave();
        for (let key in task) {
            if(Cfg.TaskCfg["daily_"+task[key]["id"]]["mode"] == mode){
                ComFun.BaseCall("taskCommit", mode, count, extras);
                return ;
            }
        }
        task = KBEngine.app.player().task_action_list;
        for (let i in task) {
            let state = task[i]["state"].split(",");
            for (let j in state) {
                if(state[j] >= 0){
                    ComFun.BaseCall("taskCommit", mode, count, extras);
                    return ;
                }
            }
        }
			
    }

    taskFinish(id:number,type:number, stage:number) : void{
        ComFun.BaseCall("taskFinish", id, type, stage);
    }
    onTaskFinish(id:number, type:number, stage:number) : void{
        taskModel.setTask();
        this.taskDlg.onTaskFinish(id,type,stage);
    }

    taskDailyActiveReceive(index):void{
        ComFun.BaseCall("taskDailyActiveReceive", index);
    }
    onTaskDailyActiveReceive(index:number){
        this.taskDlg.onTaskDailyActiveReceive(index);
    }
    
}